﻿package plugin.npcDialog.ui.panels.active
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.net.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instances.*;
    import uiresource.npcdialogs.*;
    import view.mornExtends.*;
    import view.uilt.*;
    import vo.*;

    public class SwyGame extends SwyUI implements INpcDialogContent
    {
        private var curMsg:Object;
        private var _clickLimit:int = 0;

        public function SwyGame()
        {
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            btn_jinru.clickHandler = new Handler(this.btnClickHandler);
            return;
        }// end function

        private function btnClickHandler() : void
        {
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_1:* = ItemUilt.getAllCount(this.curMsg.need);
            var _loc_2:* = ModelProxy.getValue("data", "shenweiyuFloor");
            var _loc_3:* = _loc_2 == 0 ? (1) : (_loc_2.max);
            var _loc_4:* = _loc_2 == 0 ? (1) : (_loc_2.current);
            var _loc_5:* = ModelProxy.getValue("data", "swyBossState");
            if (!ModelProxy.getValue("data", "swyBossState"))
            {
                if (_loc_1 >= (_loc_3 == _loc_4 ? (this.curMsg.num) : (0)))
                {
                    _loc_6 = getTimer();
                    if (_loc_6 > this._clickLimit)
                    {
                        Server.instance.sendBuffer(102, CMDStage.ReqEnterNextFloorMessage, null, 0, 0);
                        this._clickLimit = _loc_6 + 2000;
                    }
                }
                else
                {
                    _loc_7 = ConfigDictionary.data.item;
                    _loc_8 = ItemObject.create(_loc_7[this.curMsg.need]);
                    WarningManager.show(31, [_loc_8.name]);
                }
            }
            else
            {
                WarningManager.show(135);
            }
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:int = 0;
            var _loc_10:Object = null;
            var _loc_3:* = ConfigDictionary.data.shenweiyu;
            var _loc_4:* = ModelProxy.getValue("data", "shenweiyuFloor");
            var _loc_5:* = ModelProxy.getValue("data", "shenweiyuFloor") == 0 ? (1) : (_loc_4.max);
            var _loc_6:* = _loc_4 == 0 ? (1) : (_loc_4.current);
            this.curMsg = _loc_3[_loc_6];
            if (this.curMsg)
            {
                this.showReward(this.curMsg.reward);
                _loc_7 = ConfigDictionary.data.item;
                _loc_8 = ItemObject.create(_loc_7[this.curMsg.need]);
                _loc_8.count = _loc_5 == _loc_6 ? (this.curMsg.num) : (0);
                fi.data = _loc_8;
                _loc_9 = ItemUilt.getAllCount(this.curMsg.need);
                txt_cost.text = _loc_8.name + "*" + _loc_8.count + "(背包数量：<font color=\'#" + (_loc_9 >= this.curMsg.num ? ("53b436") : ("c72514")) + "\'>" + _loc_9 + "</font>)";
                _loc_10 = ConfigDictionary.data.monster;
                txt_get.text = "击杀<font color=\'#52B730\'><u><a href=\'event:1&" + this.curMsg.mapid + "#" + this.curMsg.mx + "#" + this.curMsg.my + "\'>" + _loc_10[this.curMsg.mid].name + "</a></u></font>可获得<font color=\'#52B730\'>" + _loc_8.name + "</font>";
                txt_get.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
                txt_get.addEventListener(TextEvent.LINK, this.doLink);
            }
            return;
        }// end function

        protected function doLink(event:TextEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            _loc_2 = event.text.split("&");
            switch(int(_loc_2[0]))
            {
                case 1:
                {
                    _loc_3 = _loc_2[1].split("#");
                    ModelProxy.change("zone", "autoMove", {x:_loc_3[1], y:_loc_3[2], tostageid:_loc_3[0], onhorse:true});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function showReward(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", ";", "#");
            list.array = _loc_3[0];
            list.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            return;
        }// end function

    }
}
